package fr.mehfile.api.database;


import android.content.Context;
import android.os.Environment;

import java.io.File;
import java.net.URL;

public class NewsFromDatabase {
    public static final String imagesDirectoryOnSdCard = "/Android/data/fr.mehfile/images";
    public static final String imagesDirectoryOnApplication = "images";
    
    private int id;
    private String title;
    private String content;
    private String date;
    private URL imageUrl;
    private String imageLocation;
    private String imageFileName;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public URL getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(URL imageUrl) {
        this.imageUrl = imageUrl;
    }

    public String getImageLocation() {
        return imageLocation;
    }

    public void setImageLocation(String imageLocation) {
        this.imageLocation = imageLocation;
    }
    
    public boolean imageNeedToDownload(Context context) {
        File dir=null;
        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
            dir = new File(Environment.getExternalStorageDirectory(),
                    imagesDirectoryOnSdCard);
            if (!dir.exists()) {
                dir.mkdirs();

            }   
        }
        else{
         dir = context.getDir(imagesDirectoryOnApplication, Context.MODE_WORLD_READABLE
                | Context.MODE_WORLD_WRITEABLE);
        }
        
        File destfile = new File(dir, getFileName());
        if (destfile.exists()) {
            return false;
        }
        return true;
    }
    
    public String getFileName(){
        String url= imageUrl.toString();
        int start=  url.lastIndexOf("/");
        imageFileName=url.substring(start+1);
         return imageFileName;
        
    }
    
    
}
